// 配置页面路由
//home
const Home = () => import('@/pages/Home')
//search 
const Search = () => import('@/pages/Search')
//login
const Login = () => import('@/pages/Login')
//register
const Register = () => import('@/pages/Register')
//detail
const Detail = () => import('@/pages/Detail')
//addcartsuccess  添加购物车成功
const AddCartSuccess = () => import('@/pages/AddCartSuccess')
//shopcart 购物车列表
const ShopCart = () => import('@/pages/ShopCart')
//trade  ----结算页面
const Trade = () => import('@/pages/Trade')
//pay  -支付页面组件
const Pay = () => import('@/pages/Pay')
//paysuccess --支付成功页面组件
const PaySuccess = () => import('@/pages/PaySuccess')
//center ---个人中心组件
const Center = () => import('@/pages/Center')
//center ---个人中心下的子组件
//center ---我的订单
const MyOrder = () => import('@/pages/Center/MyOrder')
//center ---订单详情
const OrderDetail = () => import('@/pages/Center/OrderDetail')
//center ---退款
const Refund = () => import('@/pages/Center/Refund')
//center ---退款列表
const RefundList = () => import('@/pages/Center/RefundList')

//路由数组暴露
export default[
  //home组件配置
  {path:'/',component:Home},
  //search组件配置
  { path: '/search/:keyword?', // ? 代表的是参数可有可无,都不影响路由的跳转
    component: Search,
    name:'search'
  },
  //login组件配置
  {path:'/login',component:Login,meta:{isFooterHide:true}},
  //register组件配置
  {path:'/register',component:Register,meta:{isFooterHide:true}},
  //detail->商品详情页组件
  {path:'/detail/:skuId',component:Detail},
  //addcartsucess->添加购物车成功组件
  {
    path:'/addcartsuccess/:skuNum',
    component:AddCartSuccess,  
    name:'addcartsuccess',  
  },
  //shopcart -> 购物车列表
  {path:'/shopcart',component:ShopCart,name:'shopcart'},
  //trade -> 结算页面
  {
    path: '/trade',
    component: Trade,
    beforeEnter: (to, from, next) => { 
      if (from.path === '/shopcart') {
        next()
      } else { 
        next('/shopcart')
      }
    }

  },
  //pay -> 支付页面 【支付页面存在问题，只能从购物车页面进入】
  {
    path: '/pay',
    component: Pay,
    beforeEnter: (to, from, next) => { 
      if (from.path === '/trade' || from.path ==='/center/myorder' ) {
        next()
      } else { 
        next('/trade')
      }
    }
  },
  //paysuccess -> 支付成功
  {
    path: '/paysuccess',
    component: PaySuccess,
    beforeEnter: (to, from, next) => { 
      if (from.path === '/pay') {
        next()
      } else { 
        next('/pay')
      }
    }
  },
  //center -> 个人中心
  {
    path:'/center',
    component:Center,
    name:'center',
    children:[
       {path:'myorder',component:MyOrder,name:'myorder'},
       {path:'orderdetail/:orderId',component:OrderDetail,name:'orderdetail'},
       {path:'refund',component:Refund,name:'refund'},
       {path:'refundlist',component:RefundList,name:'Refundlist'},
       {path:'',redirect:'myorder'},
    ]
  },
  //redirect --默认组件配置
  {path:'/',redirect:'/'},
]